import storage from "@/utils/storage"
// import Md5 from 'js-md5'
import { login } from '@/api'
export default function onLogin() {
  return new Promise((resolve, reject) => {
    uni.getProvider({
      service: 'oauth',
      success: ({ provider }) => {
        uni.login({
          provider,
          success: async ({ code: wx_code }) => {
            console.log(wx_code, '===请求参数===', { access_token: wx_code, login_type: 10 })
            const { code: resCode, data,  data: { access_token } } = await login({ platformInfo: 'wx_light_app', access_token: wx_code, login_type: 10 })
            if (resCode === 1000) {
              storage.setStorage('access_token', access_token)
              storage.setStorage('userInfo', data)
              resolve(data)
              // $sign = md5($post['wx_code'] . 7 . GlTjptvd4nWyQskKRHXIQW);
            }
          },
          fail(err) {
            console.log(err)
          }
        });
      }
    });
  })
}